package com.http;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;

/**
 * 
 * @ClassName:JobeEditTask
 * @Description:TODO修改招聘信息
 * @author zhuw
 * @date 2013-8-25 下午9:10:33
 */
public class JobEditTask extends AsyncTask<Object, Void, ResultString> {
	public static interface CallBack extends NetWorkCallBack {
		public abstract void procJobEdit(String msg);

	}

	CallBack callback;

	public JobEditTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultString doInBackground(Object... params) {
		ResultString data = null;
		try {
//			ArrayList<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
//
//			paramPairs.add(new BasicNameValuePair("title", params[1]));
//			paramPairs.add(new BasicNameValuePair("description", params[2]));
//			paramPairs.add(new BasicNameValuePair("demand", params[3]));
//			paramPairs.add(new BasicNameValuePair("pay", params[4]));
//			paramPairs.add(new BasicNameValuePair("deadline", params[5]));
//			paramPairs.add(new BasicNameValuePair("cat", params[6]));
//			
			HashMap<String, Object> map = (HashMap<String, Object>)params[0];
			ArrayList<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
			if (map != null && !map.isEmpty()) {
				for (Map.Entry<String, Object> entry : map.entrySet()) {
					if(!entry.getKey().equals("id")){
						paramPairs.add(new BasicNameValuePair(entry.getKey(),
								entry.getValue().toString()));
						
					}
				}
			}
			
			ResEntity re = NetConUtil.postByForm(ServerPath.JOB_EDIT_PATH
					+ map.get("id"), paramPairs);
			if (re.code == ResEntity.S_OK) {
				// User user=JsonUtil.parseUser(new JSONObject(re.jsonStr));
				// data= new ResultString(CommonData.H_FLAG_SUCCESS, null,
				// user);
				data = new ResultString(CommonData.H_FLAG_SUCCESS, null, "修改成功");

			} else if (re.code == ResEntity.S_FAILED) {

				data = new ResultString(CommonData.H_FLAG_ERROR, "code:"
						+ re.code + "    " + re.jsonStr, null);

			} else {
				data = new ResultString(CommonData.H_FLAG_ERROR, "code:"
						+ re.code + ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data = new ResultString(CommonData.H_FLAG_ERROR,
					ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultString result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procJobEdit(result.result);

		} else {
			callback.procError(result.msg);
		}

	}
}
